import time
import os
from PIL import Image
import pyautogui

# from colour import Color
# import webcolors
# from rgb_to_names import rgb_to_names

from dir_objectName import dir_objectName

import pyperclip
import subprocess




calibre_Box= pyautogui.locateOnScreen("materials/calibre1.png")
calibre_center = ((calibre_Box[0]+calibre_Box[2])/2, (calibre_Box[1]+calibre_Box[3])/2)
print('calibre_center:',calibre_center)
pyautogui.moveTo(calibre_center)
pyautogui.click()
interval = 1
for i in range(40):
    print("i:", i)
    time.sleep(interval)
    pyautogui.press("down")
    bookface_none_Box = pyautogui.locateOnScreen("materials/bookface-none.png")
    print('bookface_none_Box:',bookface_none_Box)
    if bookface_none_Box:
        print("*"*20)
        bookface_none_center=(bookface_none_Box[0]+bookface_none_Box[2]/2, bookface_none_Box[1]+bookface_none_Box[3]/2)
        pyautogui.press("e")
        pdf_mini_Box = pyautogui.locateOnScreen("materials/bookface-pdf.png")
        print('pdf_mini_Box:',pdf_mini_Box)
        if pdf_mini_Box:
            print("*"*20)
            pdf_mini_center=(pdf_mini_Box[0]+pdf_mini_Box[2]/2, pdf_mini_Box[1]+pdf_mini_Box[3]/2)
            pyautogui.moveTo(pdf_mini_center)
            pyautogui.click()
            bookface_mini_none_Box = pyautogui.locateOnScreen("materials/bookface-mini-none.png")
            if bookface_mini_none_Box:
                bookface_mini_none_center=(bookface_mini_none_Box[0]+bookface_mini_none_Box[2]/2, bookface_mini_none_Box[1]+bookface_mini_none_Box[3]/2)
                pyautogui.moveTo(bookface_mini_none_center)
                time.sleep(interval + 2)
                pyautogui.moveTo(x=783, y=479) # choose bookface
                pyautogui.click()
                pyautogui.moveTo(x=1426, y=1053) # 确定
                
                time.sleep(interval)
                confirm_Box = pyautogui.locateOnScreen("materials/确定.png") #  关闭元数据编辑页面
                confirm_center = (confirm_Box[0]+confirm_Box[2]/2, confirm_Box[1]+confirm_Box[3]/2)
                print('confirm_center:',confirm_center)
                pyautogui.moveTo(confirm_center)
                pyautogui.click()
                # 移开在   确定 按钮上的鼠标
                pyautogui.moveTo(calibre_center)
            print("#"*20)
            
        
    else:
        continue
        